<template>
  <div class="edit-contract">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="300px" class="demo-ruleForm">
  <el-form-item label="房屋Id" prop="id" >
    <el-input v-model="ruleForm.id"></el-input>
  </el-form-item>
  <el-form-item label="地址" prop="address" >
    <el-input v-model="ruleForm.address"></el-input>
  </el-form-item>
  <el-form-item label="出租方（甲方）" prop="leaser" >
    <el-input v-model="ruleForm.leaser"></el-input>
  </el-form-item>
  <el-form-item label="出租方（甲方）身份证号码" prop="leaserId" >
    <el-input v-model="ruleForm.leaserId"></el-input>
  </el-form-item>
  <el-form-item label="承租方（乙方）" prop="renter" >
    <el-input v-model="ruleForm.renter"></el-input>
  </el-form-item>
  <el-form-item label="承租方（乙方）身份证号码" prop="renterId">
    <el-input v-model="ruleForm.renterId"></el-input>
  </el-form-item>
  <el-form-item label="起租时间" prop="startime">
    <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.startime" style="width: 100%;"></el-date-picker>
  </el-form-item>
  <el-form-item label="退租时间" prop="endtime">
    <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.endtime" style="width: 100%;"></el-date-picker>
  </el-form-item>
  <el-form-item label="每月租金" prop="price">
    <el-input v-model="ruleForm.price"></el-input>
  </el-form-item>
  <el-form-item label="每月交租日（数字）" prop="payRent">
    <el-input v-model="ruleForm.payRent"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
    <el-button @click="resetForm('ruleForm')">返回</el-button>
  </el-form-item>
</el-form>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        ruleForm: {
          id: '123',
          address: '地址地址地址',
          leaser: 'xxx',
          leaserId: '6545465465',
          renter: 'cxcxc',
          renterId: '2131231',
          startime: new Date(),
          endtime: new Date(),
          price: 800,
          payRent: 22
        },
        rules: {
          id: [
            { required: true, message: '房屋id', trigger: 'blur' },
            { min: 3, max: 5, message: '长度在 3 到 6个字符', trigger: 'blur' }
          ],
          address: [
          { required: true, message: '请输入地址', trigger: 'blur' },
            { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
          ],
          leaser: [
          { required: true, message: '请输入甲方', trigger: 'blur' },
          ],
          leaserId: [
          { required: true, message: '请输入甲方身份证号码', trigger: 'blur' },
          ],
          renter: [
          { required: true, message: '请输入乙方', trigger: 'blur' },
          ],
          renterId: [
          { required: true, message: '请输入乙方身份证号码', trigger: 'blur' },
          ],
          startime: [
            {  required: true, message: '请选择日期', trigger: 'change' }
          ],
          endtime: [
            { required: true, message: '请选择时间', trigger: 'change' }
          ],
          price: [
            { required: true, message: '价格', trigger: 'change' }
          ],
          payRent: [
            { required: true, message: '交租日', trigger: 'blur' }
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
            // 提交修改数据  访问接口
            // 显示合同页面(子组件给父组件传值)
            this.$emit('child-event',false)
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
        this.$emit('child-event',false)
      }
    }
  }
</script>

<style lang="scss" scoped>
.edit-contract {
  
  .el-form {
    width: 50%;
   display: flex;
   flex-direction: column;
   margin:  0 auto;
    .el-form-item {
      margin-bottom: 8px;
    }
  }
}
</style>